﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using DynamicChart.UI.ManagementRef;

namespace DynamicChart.UI.Dialogs
{
    public partial class CreateDataSourceWindow : ChildWindow
    {
        private InternalDataSource _dataSource;

        public CreateDataSourceWindow()
        {
            InitializeComponent();

            _dataSource = new InternalDataSource();
            this.DataContext = _dataSource;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            ManagementRef.ManagementWebServiceSoapClient client = DynamicChartModule.CreateManagementProxy();
            client.SaveInternalDataSourceCompleted += new EventHandler<SaveInternalDataSourceCompletedEventArgs>(client_SaveInternalDataSourceCompleted);
            client.SaveInternalDataSourceAsync(_dataSource);
        }

        void client_SaveInternalDataSourceCompleted(object sender, SaveInternalDataSourceCompletedEventArgs e)
        {
            if (e.Error == null && e.Result.IsSuccess)
            {
                this.DialogResult = true;
            }
            else
            {
                MessageBox.Show("添加失败!");
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

